package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    GridView gridView;
//    int[] tupian = new int[10];
   int[] pics= {R.mipmap.a1,R.mipmap.a2,R.mipmap.a3,R.mipmap.a4,R.mipmap.a5,R.mipmap.a6,R.mipmap.a6,R.mipmap.a6};
    String[] titles = {"通讯录", "日历", "照相机", "时钟", "游戏", "短信", "视频", "浏览器"};
    List<Map<String, Object>> list;

    //List<String>list1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gridView = findViewById(R.id.gview);//实例化控件
        //第一步：布局（大，小），实例化控件

        //第二步：准备数据
        list = new ArrayList<>();
        getData();

        String[] from = {"biaoti", "ison"};
        int[] to = {R.id.item_btn, R.id.item_image};
        SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, list, R.layout.item, from, to);
        gridView.setAdapter(simpleAdapter);
    }

        private void getData () {
            for (int i = 0; i < titles.length; i++) {
                Map<String, Object> map = new HashMap<>();
                map.put("biaoti", titles[i]);
               map.put("ison", pics[i]);
                list.add(map);
            }

        }

    }
